package com.hnl.action.user;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.hnl.core.HNLPageDispatch;
import com.hnl.core.aware.HNLAuthAware;
import com.hnl.core.aware.HNLTalentAware;
import com.hnl.core.aware.MiscTypeAware;
import com.hnl.dao.DAOException;
import com.hnl.dao.HNLDAOFactory;
import com.hnl.dao.UserDAO;
import com.hnl.util.JSONResponseUtil;

@SuppressWarnings("serial")
public class CheckDuplicateEmail extends HttpServlet implements HNLAuthAware,
		HNLTalentAware, MiscTypeAware, HNLPageDispatch {
	public static final Logger LOG = LoggerFactory
			.getLogger(CheckDuplicateEmail.class);

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		PrintWriter writer = resp.getWriter();

		try {
			// true:exist email, false:no exist email
			ValidateResult vr = new ValidateResult();

			String email = req.getParameter("email");
			String userID = req.getParameter("userID");

			UserDAO userDAO = HNLDAOFactory.getDAOFactory(
					HNLDAOFactory.HNLDAOFACTORY).getUserDAO();
			vr.validateOK = userDAO.CheckDuplicateEmail(email, userID);

			writer.println(JSONResponseUtil.getJSONObjectString(vr));

		} catch (DAOException e) {
			LOG.error("Error to add activity!!", e);
		} finally {
			writer.close();
		}

	}

	class ValidateResult {
		boolean validateOK;
	}

}
